﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace XiaoYuStock.Core
{
    /// <summary>
    ///  autor：tiny
    ///  time：2018-06-21
    ///  description：api响应结果，结果数据为对象
    /// </summary>
    /// <typeparam name="T">返回结果类型</typeparam>
    public class ApiResult<T> : BaseApiResult
    {
        /// <summary>
        ///  autor：tiny
        ///  time：2018-06-21
        ///  description：构造函数
        /// </summary>
        public ApiResult() : base()
        {
        }

        /// <summary>
        /// 结果数据
        /// </summary>
        public T Data { get; set; }

        #region 请求成功

        /// <summary>
        ///  autor：tiny
        ///  time：2018-06-20
        ///  description：请求成功
        /// </summary>
        /// <param name="data">结果数据</param>
        /// <returns></returns>
        public ApiResult<T> Success(T data)
        {
            base.Success();

            this.Data = data;
            return this;
        }

        /// <summary>
        ///  autor：tiny
        ///  time：2018-06-20
        ///  description：请求成功
        /// </summary>
        /// <param name="data">结果数据</param>
        /// <param name="subCode">子状态码</param>
        /// <returns></returns>
        public BaseApiResult Success(T data, ApiResultSubCode subCode)
        {
            base.Success(subCode);
            this.Data = data;
            return this;
        }


        #endregion

        #region 请求失败

        /// <summary>
        ///  autor：tiny
        ///  time：2018-06-20
        ///  description：请求失败
        /// </summary>
        /// <returns></returns>
        public new ApiResult<T> Error()
        {
            base.Error();
            return this;
        }

        /// <summary>
        ///  autor：tiny
        ///  time：2018-06-20
        ///  description：请求失败
        /// </summary>
        /// <param name="msg">错误信息</param>
        /// <returns></returns>
        public new ApiResult<T> Error(string msg)
        {
            base.Error(msg);
            return this;
        }

        /// <summary>
        ///  autor：tiny
        ///  time：2018-06-20
        ///  description：请求失败
        /// </summary>
        /// <param name="subCode">子状态码</param>
        /// <returns></returns>
        public new ApiResult<T> Error(ApiResultSubCode subCode)
        {
            base.Error(subCode);
            return this;
        }

        /// <summary>
        ///  autor：tiny
        ///  time：2018-06-20
        ///  description：请求失败
        /// </summary>
        /// <param name="subCode">子状态码</param>
        /// <param name="msg">错误提醒消息</param>
        /// <returns></returns>
        public new ApiResult<T> Error(ApiResultSubCode subCode, string msg)
        {
            base.Error(subCode, msg);
            return this;
        }

        #endregion

    }
}
